﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Windows.Threading;

namespace com.ReinforceLab.AlphaRexNxtStep
{
    
    /// <summary>
    /// Window1.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window
    {
        ApplicationContext context;
        DateTime _startAt;
        DispatcherTimer _timer;        

        public MainWindow()
        {
            InitializeComponent();
            
            WindowStyle = WindowStyle.None;
            //Topmost = true;
            WindowState = WindowState.Maximized;

            context = (ApplicationContext) FindResource("app_context");
            
            _timer = new DispatcherTimer();
            _timer.IsEnabled = false;
            _timer.Tick += new EventHandler(_timer_Tick);
            _timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
        }

        private void exitButtonClick(object sender, MouseButtonEventArgs e)
        {
            context.Dispose();
            this.Close();            
        }
        private void startButtonClick(object sender, MouseButtonEventArgs e)
        {
            _timer.IsEnabled = true;
            _timer.Start();
            _startAt = DateTime.Now;
        }
        void _timer_Tick(object sender, EventArgs e)
        {
            // update timer text label
            TimeSpan span = DateTime.Now - _startAt;
            _timerTextLabel.Text =
                span.Minutes.ToString("00") + ":" +
                span.Seconds.ToString("00") + ":" +
                span.Milliseconds.ToString("000");
        }
        private void stopButtonClick(object sender, MouseButtonEventArgs e)
        {
            _timer.Stop();
            _timer.IsEnabled = false;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (context.AlphaRex.IsConnected)
            {
                context.AlphaRex.Disconnect();
            }
            else
            {
                context.AlphaRex.Connect();
            }
                    
        }
    }
}
